'use strict';

angular.module('subscriberAdmob', [])
        .run(function () {
            
            document.addEventListener('appready', function () {
                
                window.plugins.AdMob.setOptions({
                    bannerAtTop: false, // set to true, to put banner at top
                    overlap: false, // set to true, to allow banner overlap webview
                    offsetTopBar: false, // set to true to avoid ios7 status bar overlap
                    isTesting: false, // receiving test ad
                    autoShow: true // auto show interstitial ad when loaded
                });

                if (device.version.search('4.1') !== 0) {
                    console.log('ADS ON - version ' + device.version);
                    setTimeout(function () {
                        // display the banner ads
                        console.log('ads banner');
                        window.plugins.AdMob.createBannerView({
                            publisherId: 'ca-app-pub-6465819007267041/3067154813'
                        });
                    }, 2000);
                }

            }, false);



            var eventGameStart = 0;
            document.addEventListener('gamestart', function () {
                eventGameStart++;

                // popup ad every secund game start
                if (eventGameStart % 2 === 0) {
                    console.log('ads interstitial');
                    // display the interstitial ads
                    window.plugins.AdMob.createInterstitialView({
                        interstitialAdId: 'ca-app-pub-6465819007267041/5651323618'
                    });
                }
            }, false);
            
            console.log('subscriberAdmob::run');
        });